<?php

class route
{
	//取得DOCUMENT ROOT到專案"小烏龜"index.php的距離。
	public function getTortoisePrjDistance()
	{
		$str_pathToMkartDir = dirname(dirname(__FILE__));
		$str_documentRoot = $_SERVER['DOCUMENT_ROOT'];

		//如果這是台Windows的機器，把反斜線通通換成斜線。
		if(TRUE == strpos($str_pathToMkartDir, '\\'))
		{
			$str_pathToMkartDir = str_replace('\\', '/', $str_pathToMkartDir);
		}
		elseif(FALSE == strpos($str_pathToMkartDir, '\\'))
		{}

		$ary_pathToMkartDirPathElems = explode('/', $str_pathToMkartDir);
		$ary_documentRootPathElems = explode('/', $str_documentRoot);

		$pathToMkartDirPathElemCnt = count($ary_pathToMkartDirPathElems);
		$documentRootPathElemCnt = count($ary_documentRootPathElems);

		$ary_tmp = array();
		$str_pathToIndexDir = '/';
		if($pathToMkartDirPathElemCnt > $documentRootPathElemCnt)
		{
			$startIndex = $documentRootPathElemCnt;
			for($i=$startIndex ; $i<$pathToMkartDirPathElemCnt ; $i++)
			{
				$ary_tmp[] = $ary_pathToMkartDirPathElems[$i];
			}
			$str_pathToIndexDir .= implode('/', $ary_tmp);
			$str_pathToIndexDir .= '/';
		}

		return $str_pathToIndexDir;
	}
}
